/**
  ******************************************************************************
  * @file    Project/Bsp/Wdg.c
  * @author  Soing
  * @version V1.0.0
  * @date    2016-04-06
  * @brief   wdg.c module.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2015 Yuanzhi ThinkRob</center></h2>
  *
  * Licensed under Yuanzhi Liberty License Agreement V1, (the "License");
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.thinkrob.com.cn
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/

	#include "Wdg.h"
	
/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/
#define IWTG_RELOAD_TIME		( 799 )

/* Private function prototypes -----------------------------------------------*/
static void Wdg_Init( void );

/* Private variables ---------------------------------------------------------*/
F_WDG_Typedef fWdg = 
{
	.init = Wdg_Init
};

/* Private functions ---------------------------------------------------------*/

/**
  * @brief  This function to initialise Adc gpio and Dma.
  * @param  None
  * @retval None
  */ 
static void Wdg_Init( void )
{
	// Check if the system has resumed from IWDG reset 
	if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)
	{
		// IWDGRST flag set
		LED_AS4_ON;
		// Clear reset flags
		RCC_ClearFlag();
	}
	else
	{
		LED_AS4_OFF;
	}

	// IWDG timeout equal to 1.6s (the timeout may varies due to LSI frequency dispersion
	// Enable write access to IWDG_PR and IWDG_RLR registers */
	IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);

	// IWDG counter clock: 32KHz(LSI) / 64 = 500Hz
	IWDG_SetPrescaler(IWDG_Prescaler_64);

	// Set counter reload value to IWTG_RELOAD_TIME
	IWDG_SetReload(IWTG_RELOAD_TIME);

	// Reload IWDG counter
	IWDG_ReloadCounter();

	// Enable IWDG (the LSI oscillator will be enabled by hardware)
	IWDG_Enable();
}

/************************ (C) COPYRIGHT Westone Instrument ***** END OF FILE ****/

